package jmine.tec.web.servlet.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;

import jmine.tec.web.servlet.StatusExposingHttpServletResponse;

/**
 * Decora response http para permitir verificar o status da resposta. Versoes anteriores a 3.0 da servlet-api nao permitem acesso ao status
 * do response.
 * 
 * @see {StatusExposingHttpServletResponse}
 * @author Marcio Ribeiro (mmr)
 * @created Dec 9, 2011
 */
public class StatusExposingHttpServletResponseFilter implements Filter {

    /**
     * {@inheritDoc}
     */
    public void init(FilterConfig filterConfig) throws ServletException {
        // do nothing
    }

    /**
     * {@inheritDoc}
     */
    public void destroy() {
        // do nothing
    }

    /**
     * {@inheritDoc}
     */
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        chain.doFilter(request, new StatusExposingHttpServletResponse((HttpServletResponse) response));
    }
}
